package com.xingbang.uitl.configread;
import com.xingbang.uitl.constant.ConstantNum;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
/**
 * 配置文件读取
 * @author zchcpy
 */
public class ConfigSettingsUtil {
	private static ConfigSettingsUtil instance;
	private Configuration config;
	private ConfigSettingsUtil(String fileNmae) throws ConfigurationException {
		config = new PropertiesConfiguration(fileNmae);
	}
	public static synchronized ConfigSettingsUtil getInstance(String fileName) {
		try {
			instance = new ConfigSettingsUtil(fileName);
		}
		catch (ConfigurationException e) {
			throw new RuntimeException(e);
		}
		return instance;
	}
	public static void main(String[] args) {
//		String nameProperties = "application.properties";
//		String s = "";
//		s = ConfigSettingsUtil.getInstance(nameProperties).getString("userIds");
//		String s2 = "";
//		s2 = ConfigSettingsUtil.getInstance(nameProperties).getString("userIds");
//		System.out.println(s);
//		System.out.println(s = s.replace("_",","));
//		System.out.println(s2);
//		boolean a = (null == s2);
//		boolean b = ("".equals(s2));
//		boolean c = ("".equals(s2));
//		System.out.println(a);
//		System.out.println(b);
//		System.out.println(c);
	}
	/**
	 * 读取Integer类型配置
	 */
	public Integer getInteger(String key) {
		return getInteger(key, ConstantNum.Z0);
	}
	public Integer getInteger(String key, int defaultValue) {
		return config.getInteger(key, defaultValue);
	}
	/**
	 * 读取String类型配置
	 */
	public String getString(String key) {
		return config.getString(key);
	}
	/**
	 * 获取默认每页条数
	 */
	public Integer getDefaultPageSize() {
		return getInteger("default.page.size", 10);
	}
}
